//
//  ViewController.m
//  导航栏菜单
//
//  Created by 林海 on 15/12/8.
//  Copyright © 2015年 林海. All rights reserved.
//

#import "ViewController.h"
#import "LMenuController.h"
#import "UIImage+UIColor.h"
#import "CateAnimationLogin.h"

static const NSTimeInterval kICSDrawerControllerAnimationDuration = 0.5;
static const CGFloat kICSDrawerControllerOpeningAnimationSpringDamping = 0.7f;
static const CGFloat kICSDrawerControllerOpeningAnimationSpringInitialVelocity = 0.1f;
static const CGFloat kICSDrawerControllerClosingAnimationSpringDamping = .50f;
static const CGFloat kICSDrawerControllerClosingAnimationSpringInitialVelocity = 0.5f;

@interface ViewController ()
@property (nonatomic,weak) LMenuController *menuVC;
@property (nonatomic,weak) UILabel *label;
@property(nonatomic,retain)UIView *view1;
@property(nonatomic,assign)BOOL ist;
@property(nonatomic,retain)CateAnimationLogin *login;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(leftItemClick:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0,0, 40, 40);
    [button setImage: [UIImage imageNamed:@"sanheng"] forState:UIControlStateNormal];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = leftItem;
    
//    self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 50,self.view.bounds.size.width, 400)];
    
    LMenuController *menuVC = [[LMenuController alloc] init];
    menuVC.view.layer.anchorPoint = CGPointMake(0, 0);
    menuVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);
    menuVC.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
    [self addChildViewController:menuVC];
    [self.view addSubview:menuVC.view];
    
  
    
    _menuVC = menuVC;
   
}

-(void)leftItemClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
    _ist  = !_ist;
    
    if (_ist == YES) {
        self.login=[[CateAnimationLogin alloc]initWithFrame:CGRectMake(0, 50,self.view.bounds.size.width, 400)];
        
        [self.view addSubview:_login];
    }else{
        [_login removeFromSuperview];
    }
    
    
 
    
    
    
    
    
    [self.navigationController.navigationBar setBackgroundImage:  btn.selected ? [UIImage imageWithColor:[UIColor clearColor]] : [UIImage imageWithColor:[UIColor blackColor]] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor clearColor]]];
    
    [UIView animateWithDuration:kICSDrawerControllerAnimationDuration
                          delay:0
         usingSpringWithDamping:kICSDrawerControllerClosingAnimationSpringDamping
          initialSpringVelocity:kICSDrawerControllerOpeningAnimationSpringInitialVelocity
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         
                         _menuVC.view.transform = btn.selected ?CGAffineTransformIdentity : CGAffineTransformMakeRotation(-M_PI_2);
                         btn.transform = btn.selected ? CGAffineTransformMakeRotation(M_PI_2) : CGAffineTransformIdentity;
                     }
                     completion:^(BOOL finished) {
                }];
}

@end
